package com.neusoft.neuiotms.dcam.fixed.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import com.neusoft.bizcore.web.support.Searchable;
import com.neusoft.neuiotms.dcam.fixed.converter.WarehouseRecordConverter;
import com.neusoft.neuiotms.dcam.fixed.dto.WarehouseRecordDTO;
import com.neusoft.neuiotms.dcam.fixed.model.WarehouseRecord;
import com.neusoft.neuiotms.dcam.fixed.repository.WarehouseRecordRepository;
import com.neusoft.neuiotms.dcam.fixed.service.WarehouseRecordService;

@Service
public class WarehouseRecordServiceImpl implements WarehouseRecordService {

    @Autowired
    private WarehouseRecordConverter warehouseRecordConverter;
    @Autowired
    private WarehouseRecordRepository warehouseRecordRepository;

    @Override
    public List<WarehouseRecordDTO> batchCreate(final List<WarehouseRecordDTO> dtos) {
        List<WarehouseRecord> models = this.warehouseRecordConverter.toListModel(dtos);
        models = this.warehouseRecordRepository.saveAll(models);
        return this.warehouseRecordConverter.toListDTO(models);
    }

    @Override
    public List<WarehouseRecordDTO> getInfoByLocation(final String location) {
        final List<WarehouseRecord> models = this.warehouseRecordRepository.findByLocation(location);
        return this.warehouseRecordConverter.toListDTO(models);
    }

    @Override
    public Page<WarehouseRecordDTO> search(final Pageable pageable, final Searchable searchable) {
        final Page<WarehouseRecord> models = this.warehouseRecordRepository.search(pageable, searchable);
        return this.warehouseRecordConverter.toPageDTO(models);
    }

}
